package com.mindbook.vip.gawxchatinfo.service.impl.question;

import com.mindbook.vip.gawxchatinfo.entity.question.OftenAskQuestion;
import com.mindbook.vip.gawxchatinfo.exception.crud.CurdException;
import com.mindbook.vip.gawxchatinfo.mapper.question.OftenAskQuestionMapper;
import com.mindbook.vip.gawxchatinfo.service.question.OftenAskQuestionService;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @NAME: wxb
 * @DATE: 2022/6/25
 * @DESCRIPTION:
 **/
@Service
public class OftenAskQuestionServiceImpl implements OftenAskQuestionService {

    @Autowired private OftenAskQuestionMapper oftenAskQuestionMapper;


    @Override
    public Integer removeByPrimaryKey(Integer id) {
        return oftenAskQuestionMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer add(OftenAskQuestion oftenAskQuestion) {
        return oftenAskQuestionMapper.insertSelective(oftenAskQuestion);
    }

    @Override
    public Integer put(OftenAskQuestion oftenAskQuestion) {
        return oftenAskQuestionMapper.updateByPrimaryKeySelective(oftenAskQuestion);
    }

    @Override
    public Integer addSelective(OftenAskQuestion oftenAskQuestion) {
        return null;
    }

    @Override
    public OftenAskQuestion findByPrimaryKey(Integer id) {
        OftenAskQuestion oftenAskQuestion = oftenAskQuestionMapper.selectByPrimaryKey(id);
        if(oftenAskQuestion==null){
            throw new CurdException(ResultEnum.DATA_SELECT_EMPTY);
        }
        //修改阅读次数
        oftenAskQuestion.setNumberOfClick(oftenAskQuestion.getNumberOfClick() + 1);
        oftenAskQuestionMapper.updateByPrimaryKeyWithBLOBs(oftenAskQuestion);

        return oftenAskQuestion;
    }

    @Override
    public Integer saveByPrimaryKeySelective(OftenAskQuestion oftenAskQuestion) {
        return null;
    }

    @Override
    public Integer saveByPrimaryKey(OftenAskQuestion oftenAskQuestion) {
        return null;
    }

    @Override
    public List<OftenAskQuestion> findAll() {
        return null;
    }

    @Override
    public List<OftenAskQuestion> findAll(String questionStem) {
        return oftenAskQuestionMapper.selectAll(questionStem);
    }
}
